package com.fu.jdbc01.controller;


import com.fu.jdbc01.domain.Student;
import com.fu.jdbc01.service.StudentService;
import com.fu.jdbc01.service.StudentServiceImpl;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Date;

public class StudentController {
    private StudentService service = new StudentServiceImpl();

    @Test
    public void findAll() {
        ArrayList<Student> list = service.findAll();
        for (Student student : list) {
            System.out.println(student);
        }
    }

    @Test
    public void findById() {
        Student student = service.findById(3);
        System.out.println(student);
    }


    @Test
    public void insert() {
        Student student = new Student(5, "付大大", 23, new Date());
        int result = service.insert(student);

        if (result != 0) {
            System.out.println("添加成功");
        } else {
            System.out.println("添加失败");
        }
    }


    @Test
    public void update() {
        Student student = service.findById(5);
        student.setName("周奇奇");
        int result = service.update(student);

        if (result != 0) {
            System.out.println("修改成功");
        } else {
            System.out.println("修改失败");
        }
    }

    @Test
    public void delete() {
        int delete = service.delete(5);
        if (delete != 0) {
            System.out.println("删除成功");
        } else {
            System.out.println("删除失败");
        }
    }

}
